home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DJGPP
/
DJLSR111.ZIP
/
libsrc
/
c
/
gen
/
getgrent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-26
|
1KB
|
83 lines
/*
(c) Copyright 1992 Eric Backus
This software may be used freely so long as this copyright notice is
left intact. There is no warrantee on this software.
*/
#include <grp.h>
#include <string.h> /* For strcmp() */
#include <stdlib.h> /* For getenv(), getgid() */
static struct group gr;
static char *null_ptr = NULL;
static int counter = 0;
static void
fill_in()
{
char *p;
p = getenv("GROUP");
if (p)
gr.gr_name = p;
else
gr.gr_name = "other";
gr.gr_passwd = "*";
gr.gr_gid = getgid();
gr.gr_mem = &null_ptr;
}
struct group *
getgrent(void)
{
if (counter == 0)
{
counter++;
fill_in();
return &gr;
}
return NULL;
}
struct group *
fgetgrent(FILE *f)
{
if (counter == 0)
{
counter++;
fill_in();
return &gr;
}
return NULL;
}
struct group *
getgrgid(int gid)
{
fill_in();
if (gr.gr_gid == gid) return &gr;
return NULL;
}
struct group *
getgrnam(char *name)
{
fill_in();
if (strcmp(gr.gr_name, name) == 0) return &gr;
return NULL;
}
void
setgrent(void)
{
counter = 0;
}
void
endgrent(void)
{
counter = 0;
}